#!/usr/bin/env python
# encoding: utf-8
"""
#-------------------------------------------------------------------#
#                   CONFIDENTIAL --- CUSTOM STUDIOS                 #     
#-------------------------------------------------------------------#
#                                                                   #
#                   @Project Name : 全球法律在线项目                #
#                                                                   #
#                   @File Name    : Main.py                      #
#                                                                   #
#                   @Programmer   : 李建                            #
#                                                                   #  
#                   @Start Date   : 2020-12-16 17:25                 #
#                                                                   #
#                   @Last Update  : 2020-12-16 17:25                 #
#                                                                   #
#-------------------------------------------------------------------#
# Classes:                                                          #
#                                                                   #
#-------------------------------------------------------------------#
"""
import datetime

from LawExport.ExportLaw import ExportLaw
from LawNewsExport.ExportNews import ExportNews
from apscheduler.schedulers.blocking import BlockingScheduler


def exportnews():
    print(str(datetime.datetime.now()) + "：法制新闻自动导出服务正在运行")
    extn = ExportNews()
    extn.export_news()
    print(str(datetime.datetime.now()) + "：法制新闻自动导出结束")

def exportlaw():
    print(str(datetime.datetime.now()) + "：法律文件自动导出服务启动")
    extl = ExportLaw()
    extl.download_law()    # 先将境外服务器上的法律文件下载到采集服务器上
    extl.export_law()   # 将采集服务器上的法律文件上传到web服务器中
    print(str(datetime.datetime.now()) + "：法律文件自动导出结束")

def main():
    scheduler = BlockingScheduler()
    scheduler.add_job(exportnews, 'cron', hour='5,17')
    scheduler.add_job(exportlaw, 'cron', day_of_week = '5', hour='22', max_instances=2)  # day_of_week = '6',minute='59'max_instances可以同时运行两个线程
    print("新闻导出服务将在每天的5点和17点启动\n法律文件导出服务将在每周六22：00启动")
    scheduler.start()

if __name__ == '__main__':
    main()
